package dmmm.main;

import java.io.*;

public class StepsLoader {

	private String[] steps;// koji su signali aktivni
	private String[] desc;// sa uzvicnicima
	private int currStepNumber;

	public StepsLoader(String stepsConfFile, PrintStream log) {
		steps = new String[240];
		desc = new String[240];
		currStepNumber = 0;

		if (log == null) {
			log = System.out;
		}

		long begin = System.currentTimeMillis();

		log.println();
		log.println("StepLoader:");
		log.println();

		try {
			BufferedReader reader = new BufferedReader(new FileReader(
					stepsConfFile));
			String line = reader.readLine();

			while (line != null) {

				if (line.charAt(0) == '!') {
					desc[currStepNumber] = line;

				} else if (line.charAt(0) == 'm') {

					// currStep = line.substring(6, line.length());
					steps[currStepNumber++] = line;
				} else {

				}

				line = reader.readLine();
			}

			reader.close();
			log.println("time taken: " + (System.currentTimeMillis() - begin)
					+ " ms");
		} catch (FileNotFoundException e) {
			log.println("Conf file not found!");
		} catch (IOException e) {
			log.println("Conf file corrupted!");
		}
	}

	public String[] getSteps() {
		return steps;
	}

	public String[] getDesc() {
		return desc;
	}

	public String getStepsAt(int n) {
		return steps[n];
	}

	public String getDescAt(int n) {
		return desc[n];
	}
	public String allSteps(){
		StringBuffer s=new StringBuffer();
		for(String str:steps){
			if(str!=null){
				s.append(str+"\n");
			}
		}
		return s.toString();
	}

	public static void main(String[] args) {
		// String[] steps = new StepsLoader("src/main/microProgram.txt",
		// null).getSteps();
		// String[] desc = new StepsLoader("src/main/microProgram.txt",
		// null).getDesc();
		// for(int i = 0; i < steps.length; i++) {
		// if(steps[i]!=null){
		// System.out.println(Integer.toHexString(i)+" : "+steps[i]);
		// }
		// }
		// for(int i = 0; i < desc.length; i++) {
		// if(desc[i]!=null){
		// System.out.println(Integer.toHexString(i)+" : "+desc[i]);
		// }
		// }
	}
}
